<?php
class ResolveIssueForm extends Zend_Form
{
	public function init()
	{
		$fronController = Zend_Controller_Front::getInstance();
		$request = $fronController->getRequest();
		$issueId = $request->getParam('id');
		$issue = new Issue();
		$pid = $issue->getAdapter()->fetchOne($issue->select()->from('issue','project')
															->where('id=?',$issueId));
		
		$users = new UserBase();
		$usersList = $users->getUsersList();
		
		$projectVersion = new ProjectVersion();
		$versionsList = $projectVersion->getList($pid);
		
		$resolution = new Resolution();
		$resolutionList = $resolution->getResolutionList();
		
		$id = $this->createElement('hidden','id');
		$id->setValue($issueId)
				->setDecorators(array(
							'viewHelper',
							'Errors',
							array('Description', array('tag'=>'', 'escape'=>false)),
							array(array('data'=>'HtmlTag'),
								array('tag'=>'td', 'valign'=>'top','colspan'=>2,'style'=>'background-color:#ffffff')),
							//array('Label', array('tag'=>'td')),
							array(array('row'=>'HtmlTag'), array('tag'=>'tr'))
				));
		
		$resolution = $this->createElement('select','resolution');
		$resolution->setLabel('* Resolution:')
					->addMultioptions($resolutionList)
					->setRequired(true);
					
		$fixVersion = $this->createElement('multiselect','fixVersion');
		$fixVersion->setLabel('Fix Version:')
					->addMultioption('','Unreleased Versions')
					->addMultioptions($versionsList);
		
		$assignee = $this->createElement('select','assignee');
		$assignee->setLabel('Assignee:')
					->addMultioption('','- Automatic -')
					->addMultioptions($usersList);
					
		$comments = $this->createElement('textarea','comments');
		$comments->setLabel('Comments:')
				->setAttrib('rows',15);
		
		$resolve = $this->createElement('submit','resolve');
		$resolve->setLabel('Resolve')
				->setIgnore(true)
				->setDecorators(array(
								'viewHelper',
								'Errors',
								array('Description',array('tag'=>'','escape'=>false)),
								array(array('data'=>'HtmlTag'),
									array('tag'=>'td','align'=>'center','style'=> 'background-color:#ffffff;text-align:center','colspan'=>2,'openOnly'=>true)),
								array(array('row'=>'HtmlTag'),
										array('tag'=>'tr','openOnly'=>true))
								));
		
		$cancel = $this->createElement('button','cancel');
		$cancel->setLabel('Cancel')
				->setIgnore(true)
				->setDecorators(array(
								'viewHelper',
								'Errors',
								array('Description',array('tag'=>'','escape'=>false)),
								array(array('data'=>'HtmlTag'),
									array('tag'=>'td','closeOnly'=>true)),
								array(array('row'=>'HtmlTag'),
										array('tag'=>'tr','closeOnly'=>true))
								));
								
		$this->addElements(array(
					$resolution,
					$fixVersion,
					$assignee,
					$comments,
					$id,
					$resolve,
					$cancel
		));
		
		$this->setElementDecorators(array(
								'viewHelper',
								'Errors',
								array('Description',array('tag'=>'','escape'=>false)),
								array(array('data'=>'HtmlTag'), array('tag'=>'td','style'=> 'background-color:#ffffff;text-align:left','width'=>'75%')),
								array('Label',array('tag'=>'td')),
								array(array('row'=>'HtmlTag'),array('tag'=>'tr'))
								),array('resolution','fixVersion','assignee','comments'));
								
		$this->setDecorators(array(
    			'FormElements',
    			array('HtmlTag', array('tag' => 'table','cellspacing'=>'0','cellpadding'=>'0','border'=>'0','width'=>'100%','class'=>'pform')),
    			'Form',
				));
		
	}
}